# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: xguo

from coin.exchange.base.kr_rest.product import NativeProduct
from coin.exchange.coinone_v2.kr_rest.currency import CoinoneCurrency


class CoinoneProduct(NativeProduct):
  _exchange = "Coinone"
  NativeCurrencyType = CoinoneCurrency
  _quote = CoinoneCurrency.FromStr('KRW')

  def __init__(self, base, quote):
    native_currency = base.native_currency
    assert quote.currency == 'KRW', quote
    super().__init__(base, self._quote, native_currency)
    self._native_subscription_symbol = '%s-krw' % base.native_currency

  @property
  def native_subscription_symbol(self):
    return self._native_subscription_symbol

  @classmethod
  def FromStrNativeProductImpl(cls, product, current_datetime):
    pair = product.split('-')
    if len(pair) == 1:
      assert isinstance(product, str), type(product)
      base = CoinoneCurrency.FromStrNativeCurrency(product)
      return cls(base, cls._quote)
    elif len(pair) == 2:
      base = CoinoneCurrency.FromStrNativeCurrency(pair[0])
      quote = CoinoneCurrency.FromStrNativeCurrency(pair[1])
      return cls(base, quote)
